package com.bosch.in.rtp1.ept.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

import com.bosch.in.rtp1.ept.action.form.FrozenColumnForm;
import com.bosch.in.rtp1.ept.manager.FrozenColumnManager;
import com.bosch.in.rtp1.ept.util.ManagerFactory;


public class FrozenColumnAction extends MappingDispatchAction{
	
	private static final Logger LOGGER = Logger.getLogger(FrozenColumnAction.class);
	
	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws SQLException 
	 */
	public ActionForward saveFrozenColumn(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response) throws SQLException 
			 {
		
		LOGGER.debug("Begin saveFrozenColumn");
		
		// create skipped FrozenColumn manager instance
		FrozenColumnManager frozenColumnManager = ManagerFactory.getInstance().getFrozenColumnManager();
		
		// insert to database
		frozenColumnManager.updateFrozenColumn((FrozenColumnForm)form);
		
		LOGGER.debug("End saveFrozenColumn");
		
        return mapping.findForward("success");
	}
	
	/**
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws SQLException 
	 */
	public ActionForward loadFrozenColumn(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response) throws SQLException 
			 {
		LOGGER.debug("Begin loadFrozenColumn");
		
		// create skipped FrozenColumn manager instance
		FrozenColumnManager frozenColumnManager = ManagerFactory.getInstance().getFrozenColumnManager();
		
		FrozenColumnForm froForm =  frozenColumnManager.getFrozenColumnForm();
		((FrozenColumnForm)form).setLotStatusCols(froForm.getLotStatusCols()); 
		((FrozenColumnForm)form).setReleasedHoldCols(froForm.getReleasedHoldCols()); 
		((FrozenColumnForm)form).setLotStatusStartScrollingCol(froForm.getLotStatusStartScrollingCol());
		((FrozenColumnForm)form).setReleasedHoldStartScrollingCol(froForm.getReleasedHoldStartScrollingCol());
		
		LOGGER.debug("End loadFrozenColumn");
        return mapping.findForward("success");
	}
}
